package plugin.demo.shardingsphere.xa.config;//package authentication.config;
//
//import com.zaxxer.hikari.HikariDataSource;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.boot.jdbc.DataSourceBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.TransactionManager;
//import tk.mybatis.spring.annotation.MapperScan;
//
//import javax.sql.DataSource;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @Author: Qiao Hang
// * @CreateDate: 2021/4/20 下午4:00
// * @UpdateDate:
// * @Description:
// */
//@Configuration
//@MapperScan(basePackages = "authentication.mappers",
//        sqlSessionFactoryRef = "sqlSessionFactory")
////@org.mybatis.spring.annotation.MapperScan()
//public class DataSourceConfig {
//
//    @Bean("masterDataSource")
//    @Primary
//    public DataSource master() {
//        HikariDataSource master = DataSourceBuilder.create()
//                .type(HikariDataSource.class)
//                .username("root")
//                .password("root")
//                .driverClassName("com.mysql.cj.jdbc.Driver")
//                .url("jdbc:mysql://118.31.13.167:3306/test?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT")
//                .build();
//        return master;
//    }
//
//    @Bean("slave0DataSource")
//    public DataSource slave0() {
//        HikariDataSource slave0 = DataSourceBuilder.create()
//                .type(HikariDataSource.class)
//                .username("root")
//                .password("root")
//                .driverClassName("com.mysql.cj.jdbc.Driver")
//                .url("jdbc:mysql://118.31.13.167:3307/test?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT")
//                .build();
//        return slave0;
//    }
//
//    @Bean("slave1DataSource")
//    public DataSource slave1() {
//        HikariDataSource slave0 = DataSourceBuilder.create()
//                .type(HikariDataSource.class)
//                .username("root")
//                .password("root")
//                .driverClassName("com.mysql.cj.jdbc.Driver")
//                .url("jdbc:mysql://118.31.13.167:3308/test?userSSL=true&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT")
//                .build();
//        return slave0;
//    }
//
//    @Bean("dynamicDataSource")
//    public DataSource dynamicDataSource() {
//        Map<Object, Object> dataSourceMap = new HashMap<>(2);
//        dataSourceMap.put("master", master());
//        dataSourceMap.put("slave0", slave0());
//        dataSourceMap.put("slave1", slave1());
//
//        DynamicDataSource dynamicDataSource = new DynamicDataSource(dataSourceMap);
//        dynamicDataSource.setDefaultTargetDataSource(master());
//        return dynamicDataSource;
//    }
//
//
//    @Bean("sqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory() throws Exception {
//        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//        // 配置数据源，此处配置为关键配置，如果没有将 dynamicDataSource作为数据源则不能实现切换
//        sessionFactory.setDataSource(dynamicDataSource());
//        SqlSessionFactory object = sessionFactory.getObject();
//        return object;
//    }
//
//    @Bean
//    public DataSourceTransactionManager transactionManager() {
//        return new DataSourceTransactionManager(dynamicDataSource());
//    }
//
//    public enum DBRouter{
//        Master,
//        Slave;
//    }
//}
